package com.ruoyi.wechat.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wechat.domain.ScenicSpots;
import com.ruoyi.wechat.service.IScenicSpotsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 周边景点Controller
 * 
 * @author ruoyi
 * @date 2024-07-26
 */
@RestController
@RequestMapping("/camp/spots")
public class ScenicSpotsController extends BaseController
{
    @Autowired
    private IScenicSpotsService scenicSpotsService;

    /**
     * 查询周边景点列表
     */
    @PreAuthorize("@ss.hasPermi('camp:spots:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScenicSpots scenicSpots)
    {
        startPage();
        List<ScenicSpots> list = scenicSpotsService.selectScenicSpotsList(scenicSpots);
        return getDataTable(list);
    }

    /**
     * 导出周边景点列表
     */
    @PreAuthorize("@ss.hasPermi('camp:spots:export')")
    @Log(title = "周边景点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScenicSpots scenicSpots)
    {
        List<ScenicSpots> list = scenicSpotsService.selectScenicSpotsList(scenicSpots);
        ExcelUtil<ScenicSpots> util = new ExcelUtil<ScenicSpots>(ScenicSpots.class);
        util.exportExcel(response, list, "周边景点数据");
    }

    /**
     * 获取周边景点详细信息
     */
    @PreAuthorize("@ss.hasPermi('camp:spots:query')")
    @GetMapping(value = "/{scenicId}")
    public AjaxResult getInfo(@PathVariable("scenicId") String scenicId)
    {
        return success(scenicSpotsService.selectScenicSpotsByScenicId(scenicId));
    }

    /**
     * 新增周边景点
     */
    @PreAuthorize("@ss.hasPermi('camp:spots:add')")
    @Log(title = "周边景点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScenicSpots scenicSpots)
    {
        return toAjax(scenicSpotsService.insertScenicSpots(scenicSpots));
    }

    /**
     * 修改周边景点
     */
    @PreAuthorize("@ss.hasPermi('camp:spots:edit')")
    @Log(title = "周边景点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScenicSpots scenicSpots)
    {
        return toAjax(scenicSpotsService.updateScenicSpots(scenicSpots));
    }

    /**
     * 删除周边景点
     */
    @PreAuthorize("@ss.hasPermi('camp:spots:remove')")
    @Log(title = "周边景点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scenicIds}")
    public AjaxResult remove(@PathVariable String[] scenicIds)
    {
        return toAjax(scenicSpotsService.deleteScenicSpotsByScenicIds(scenicIds));
    }

}
